package com.mdc.mansion.api.web.modules.report;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.mdc.mansion.api.web.common.web.BaseController;
import com.mdc.mansion.common.response.Result;
import com.mdc.mansion.common.response.ResultCode;
import com.mdc.mansion.core.common.restaurant.RestaurantCommon;
import com.mdc.mansion.core.modules.order.RestaurantOrderService;
import com.mdc.mansion.core.modules.report.RestaurantReportService;

@Controller
@RequestMapping(value = "${adminPath}/report")
public class RestaurantReportController extends BaseController {
	
    @Resource
	private RestaurantReportService restaurantReportService;
    
    @Resource
    private RestaurantOrderService restaurantOrderService;
    
    /**
     * 2018年2月3日 12:17:58
     * controller 分为日、天、月、年查询，后端区分查询类型，按类型进行查询
     * 
     */
    
		
	    /**
	    * 查询报表,按天查询,一次返回所有菜品
	   * 营收额报表 销售总金额 totalAmountList
			各菜品分类销售情况-金额 categoryAmountList
			各菜品销售情况-金额 dishesAmountList
			各菜品销量情况-数量 dishesCountList
	    *  入参: 开始日期，可以查询从开始日期往后7天的数据
		 * @return
		 */
		@RequestMapping(value = "/reportDay",method  = RequestMethod.POST)
		public Result reportDay(String data)
		{
			Result restultResult = new Result(ResultCode.COMMON_SUCCESS);
			List<Map<String, Object>> totalAmountList =  restaurantReportService.getTotalAmountList(RestaurantCommon.ReportType_Day,data);
			List<Map<String, Object>> categoryAmountList = restaurantReportService.getCategoryAmountList(RestaurantCommon.ReportType_Day,data);
			List<Map<String, Object>> dishesAmountList = restaurantReportService.getDishesAmountList(RestaurantCommon.ReportType_Day,data);
			restultResult.setProperty("totalAmountList", totalAmountList);
			restultResult.setProperty("categoryAmountList", categoryAmountList);
			restultResult.setProperty("dishesAmountList", dishesAmountList);
			return restultResult;
		}
		
	    /**
	    * 查询报表,按月查询,一次返回所有菜品
	    * 营收额报表 销售总金额 totalAmountList
			各菜品分类销售情况-金额 categoryAmountList
			各菜品销售情况-金额 dishesAmountList
			各菜品销量情况-数量 dishesCountList
			入参: 开始日期，可以查询从开始日期往后30天的数据
		 * @return
		 */
		@RequestMapping(value = "/reportMonth",method  = RequestMethod.POST)
		public Result reportMonth(String data)
		{
			Result restultResult = new Result(ResultCode.COMMON_SUCCESS);
			List<Map<String, Object>> totalAmountList =  restaurantReportService.getTotalAmountList(RestaurantCommon.ReportType_Year,data);
			List<Map<String, Object>> categoryAmountList = restaurantReportService.getCategoryAmountList(RestaurantCommon.ReportType_Month,data);
			List<Map<String, Object>> dishesAmountList = restaurantReportService.getDishesAmountList(RestaurantCommon.ReportType_Month,data);
			restultResult.setProperty("totalAmountList", totalAmountList);
			restultResult.setProperty("categoryAmountList", categoryAmountList);
			restultResult.setProperty("dishesAmountList", dishesAmountList);
			return restultResult;
		}
	
	
	   /**
	    * 查询报表,按年查询,一次返回所有菜品
	    * 
	    * 营收额报表 销售总金额 totalAmountList
			各菜品分类销售情况-金额 categoryAmountList
			各菜品销售情况-金额 dishesAmountList
			各菜品销量情况-数量 dishesCountList
			入参: 开始日期，可以查询从开始日期往后一年的数据
			不足一年则查询当年1月1日到当前的数据
		 * @return
		 */
		@RequestMapping(value = "/reportYear",method  = RequestMethod.POST)
		public Result reportYear(String data)
		{
			Result restultResult = new Result(ResultCode.COMMON_SUCCESS);
			List<Map<String, Object>> totalAmountList = restaurantReportService.getTotalAmountList(RestaurantCommon.ReportType_All_Year,data);
			List<Map<String, Object>> categoryAmountList = restaurantReportService.getCategoryAmountList(RestaurantCommon.ReportType_Year,data);
			List<Map<String, Object>> dishesAmountList =restaurantReportService.getDishesAmountList(RestaurantCommon.ReportType_Year,data);
			restultResult.setProperty("totalAmountList", totalAmountList);
			restultResult.setProperty("categoryAmountList", categoryAmountList);
			restultResult.setProperty("dishesAmountList", dishesAmountList);
			return restultResult;
		}
	
//	@RequestMapping(value = "/reportAllYear",method  = RequestMethod.POST)
//	public Result reportAllYear(String data)
//	{
//		Result restultResult = new Result(ResultCode.COMMON_SUCCESS);
//		List<Map<String, Object>> totalAmountList = restaurantReportService.getTotalAmountList(RestaurantCommon.ReportType_All_Year,data);
//		List<Map<String, Object>> categoryAmountList = restaurantReportService.getCategoryAmountList(RestaurantCommon.ReportType_All_Year,data);
//		List<Map<String, Object>> dishesAmountList =restaurantReportService.getDishesAmountList(RestaurantCommon.ReportType_All_Year,data);
//		restultResult.setProperty("totalAmountList", totalAmountList);
//		restultResult.setProperty("categoryAmountList", categoryAmountList);
//		restultResult.setProperty("dishesAmountList", dishesAmountList);
//		return restultResult;
//	}
			
			   /**
			    * 绩效报表
			    * 服务员销售统计
					收银员收银金额统计
					优惠金额统计 --- 优惠金额统计采用日期报表的SQL既可
					退菜金额统计
					撤销订单统计
				入参：起始日期
				 * @return
				 */
		@RequestMapping(value = "/reportPerformance",method  = RequestMethod.POST)
		public Result reportPerformance(String data)
		{
			List<Map<String,Object>> resultList = new ArrayList<Map<String,Object>>();
			Result restultResult = new Result(ResultCode.COMMON_SUCCESS);
			
			resultList = restaurantReportService.getWaitersTotalMoney(data);
			restultResult.setProperty("waitersTotalMoney", resultList);
			resultList = restaurantReportService.getCashierTotalMoney(data);
			restultResult.setProperty("cashierTotalMoney", resultList);
			resultList = restaurantReportService.getTotalDiscountMoney(data);
			restultResult.setProperty("totalDiscountMoney", resultList);
			resultList = restaurantReportService.getCancelDishesTotalMoney(data);
			restultResult.setProperty("cancelDishesTotalMoney", resultList);
			resultList = restaurantReportService.getCancelOrderTotalMoney(data);
			restultResult.setProperty("cancelOrderTotalMoney", resultList);
			
			return restultResult;
		}	
			
			
			
			

}
